<script setup>
import { ref } from "vue"
import { defineProps } from "vue"
import { useRoute } from "vue-router"
import PandaBookPopup from "@/components/book-popup/PandaBookPopup.vue"
import { getSalesVolume } from "@/utils/index.js"


const props = defineProps({
  data: Object,
  scenicVoteList: Array,
  scenicSpotTicketId: String,
  voteDetail: Object
});
const show = ref(false);
const route = useRoute();
const scenicId = route.params.id;
const dateInfoArraylist = ref([]);
const ydvalue = ref(false);
const goodsKindsInfolist = ref([]);
const sessionlist = ref([]);
const minDate = ref(null);
const maxDate = ref(null);
const marketPrice = ref(null);
const items = ref();
const ids = ref();
const scenicSpotTicketids = ref([]);

// 弹出框
const productId = ref("");
const sortid = ref("");

const itemVoteDetail = ref(null)
const handelyud = (item, id, scenicSpotTicketid) => {
  itemVoteDetail.value = item
  marketPrice.value = item.unitPriceStandard
  productId.value = item.id
  show.value = true
  sortid.value = scenicSpotTicketid
};

const closePopup = () => {
  show.value = false;
};

const closeClick = () => {
  ydvalue.value = false
}
const handelyudss = () => {
  ydvalue.value = false;
  handelyud(items.value, ids.value, scenicSpotTicketids.value);
};

const buyNote = ref(null)
const handelshowBottom = (data) => {
  buyNote.value = JSON.parse(data.buyNote)
  ydvalue.value = true
}

</script>
<template>
  <div class="header">
    <h1 class="title">{{ voteDetail?.peopleGroupStr }}</h1>
    <div class="line" />
  </div>
  <div class="ticket">
    <div class="card" v-for="item in voteDetail.list" :key="item.id">
      <div class="card_left">
        <span class="name">{{ item?.ticketName }}</span>
        <div class="tab_list">
          <span v-if="item?.sellCount" class="tab sales_volume">
            月售{{ getSalesVolume(item?.sellCount) }}
            <span v-if="(item?.sellCount > 100)">+</span>
          </span>
          <div class="tab" @click="handelshowBottom(item)">
            <span class="booking_instructions">预订须知</span>
            <van-icon name="arrow" />
          </div>
        </div>
      </div>
      <div class="card_right">
        <div class="price_box">
<!--          <div v-if="item.unitPriceStandard" class="market_price">-->
<!--            ￥{{ item.unitPriceStandard }}-->
<!--          </div>-->
          <div class="price">
            ￥
            <span class="number">
              {{ item?.unitPriceStandard }}
            </span>
            起
          </div>
        </div>
        <div class="book_button" @click="handelyud(item, 1, props?.scenicSpotTicketId?.[0]?.id)">预订</div>
      </div>
    </div>
  </div>
  <van-popup v-model:show="ydvalue" round position="bottom" :style="{ 'max-height': '70%' }" teleport="body">
    <div class="intro">
      <div class="intro_header">
        <div class="title">预订须知</div>
        <img class="image_close" @click="closeClick" src="@/assets/images/icons/close-666666.png" alt="">
      </div>
      <div class="content">
        <div class="content_text_box">
          <div class="content_list" v-for="(item, _, index) in buyNote.resourceAddInfoList" :key="index">
            <h1 v-if="!(item[0].title === '预订说明' && !index)" class="content_list_title">
              {{ item[0].title }}
            </h1>
            <div class="content_list_content" v-for="(ite, inde) in item" :key="inde">
              <div class="content_list_content_title_box">
                <h2 class="content_list_content_title" :class="{active_title: item[0].title === '预订说明' && !index}">{{ ite.subTitle }}</h2>
              </div>
              <div class="content_list_content_content">
                <div v-for="(it, ind) in ite.resourceAddInfoDetailList" :key="ind">
                  {{ it.descDetail }}
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="bottom">
          <div class="book">
            <div class="intro_book_button" @click="handelyudss">预订</div>
            <div class="intro_price">
              <span class="text">应付金额：</span>
              <div class="price_box">
                <span class="icon">
                  ￥
                </span>
                <span class="number">
                  {{ buyNote?.price }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </van-popup>
  <PandaBookPopup v-if="show" :scenicDetail="props.data" :showPopup="show" :voteDetail="voteDetail" @closePopup="closePopup" :goodsKindsInfolist="goodsKindsInfolist"
    :sessionlist="sessionlist" :dateInfoArraylist="dateInfoArraylist" :minDate="minDate" :maxDate="maxDate"
    :scenicId="scenicId" :sortid="sortid" :marketPrice="marketPrice" :productId="productId" :itemVoteDetail="itemVoteDetail" />
</template>

<style lang="scss" scoped>
.header {
  margin-left: 2rem;

  .title {
    font-weight: bold;
    font-size: 1.8rem;
    color: #333333;
  }

  .line {
    // border-bottom: 2px solid red;
    // width: 3rem;
    // height: 0.6rem;
    // background: linear-gradient(90deg, #4FAC91 0%, #ECE3AA 83%);
    // border-radius: .3rem;
    // margin-top: -0.2rem;
  }
}

.ticket {
  margin: 1rem 2rem 1.5rem 2rem;
  background: #FFFFFC;
  box-shadow: 0 .7rem 1.5rem 0 rgba(54, 141, 88, 0.05);
  border-radius: 1rem;

  .card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 1rem;
    border-bottom: .1rem #EEEEEE solid;

    .card_left {
      .name {
        font-size: 1.6rem;
        color: #333333;
        font-weight: bold;
        line-height: 2.2rem;
      }

      .tab_list {
        display: flex;
        flex-wrap: wrap;
        margin-top: .8rem;

        .tab {
          display: flex;
          align-items: center;
          margin-right: .8rem;
          height: 1.7rem;
          line-height: 1.7rem;
          font-size: 1.2rem;
          color: #999999;
          margin-bottom: .2rem;

          .booking_instructions {
            margin-right: .2rem;
          }
        }

        .sales_volume {
          height: 1.7rem;
          line-height: 1.7rem;
          background: rgba(79, 172, 145, 0.1);
          border-radius: .3rem;
          padding: 0 .5rem;
          font-size: 1.2rem;
          color: var(--van-primary-color);
        }
      }
    }

    .card_right {
      display: flex;
      align-items: center;

      .price_box {
        display: flex;
        align-items: baseline;
        letter-spacing: -0.2rem;

        .market_price {
          text-decoration: line-through;
          font-size: 1.4rem;
          color: #999999;
        }

        .price {
          white-space: nowrap;
          margin-left: .5rem;
          margin-right: 1rem;
          font-size: 1.2rem;
          color: #ED6316;

          .number {
            font-size: 2.2rem;
          }
        }
      }

      .book_button {
        height: 3rem;
        background: var(--van-primary-color);
        border-radius: .5rem;
        font-size: 1.4rem;
        color: #FFFFFF;
        line-height: 3rem;
        padding: 0 1.5rem;
        white-space: nowrap;
      }

      .book_button:active {
        background-color: var(--van-primary-button-active-color);
      }
    }
  }
}

.van-stepper>.van-stepper__input {
  width: 5rem !important;
}

.intro {
  display: flex;
  flex-direction: column;
  padding: 2rem;
  overflow: hidden;
  // height: 100%;

  .intro_header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 2.8rem;
    margin-bottom: 1.5rem;

    .title {
      font-size: 2rem;
      font-weight: bold;
    }

    .image_close {
      width: 1.4rem;
      height: 1.4rem;
    }
  }

  .content {
    max-height: calc(70vh - 4rem - 2.8rem - 1.5rem);
    display: flex;
    flex-direction: column;
    .content_text_box {
      flex: 1;
      overflow-y: auto;
      .content_list{
        .content_list_title{
          font-size: 2rem;
          font-weight: bold;
          color: #2F3836;
          margin-bottom: 1.5rem;
        }
        .content_list_content{
          display: flex;
          margin-bottom: 2rem;
          .content_list_content_title_box{
            width: 6.6rem;
            margin-right: 1.4rem;
            .content_list_content_title{
              display: inline;
              white-space:nowrap;
              background: rgba(0,0,0,0.05);
              color: #666666;
              border-radius: .3rem;
              padding: 0 .5rem;
              font-size: 1.4rem;
              height: 2rem;
              line-height: 2rem;
            }
            .active_title{
              background: rgba(79,172,145,0.1);
              color: var(--van-primary-button-active-color);
            }
          }
          .content_list_content_content{
            flex: 1;
            font-size: 1.4rem;
            color: #666666;
            line-height: 2rem;
          }
        }
      }
    }
    .bottom {
      height: 5rem;
      background: #FFFFFF;
      .book {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        padding: 1rem;

        .intro_book_button {
          height: 3.8rem;
          background: var(--van-primary-color);
          border-radius: .5rem;
          padding: 0 3rem;
          font-size: 1.6rem;
          color: #FFFFFF;
          line-height: 3.8rem;
        }

        .intro_book_button:active {
          background-color: var(--van-primary-button-active-color);
        }

        .intro_price {
          display: flex;
          align-items: center;
          margin-right: 1rem;

          .text {
            font-size: 1.4rem;
            color: #999999;
          }

          .price_box {
            display: flex;
            align-items: baseline;
            font-weight: bold;

            .icon {
              font-size: 1.4rem;
              color: #ED6316;
            }

            .number {
              font-size: 2.2rem;
              color: #ED6316;
            }
          }
        }
      }
    }
  }
}

</style>